
/*remise dans le bon sens de masque-var*/
-- masque_var_trans;


define erp='erp_mli2.';
define outils='outils_mli2.';


 /*
select * from (
SELECT &outils.stragg(source) source,champsais_cod, champsais_lib, enreg_s, longueurgraph_val, format_val, originecreat_val,champsaisorig_cod , unite_cod, enreg_id, champsais_lib2, pgi_typ, champ_typ, longueursais_val, precision_val, converscass_typ, saisie_ok, visible_ok, obligfocus_ok, obligval_ok, rubriqueaide_cod, msgaide_lib, infobulle_lib, presentation_typ, implicite_val
FROM (
  SELECT 'uv' source ,g.* FROM se_GEN_CHAMPSAIS g where exists (select 1 from se_ART_GENECHAPATT a where a.champsais_cod=g.champsais_cod)
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.GEN_CHAMPSAIS g where exists (select 1 from &erp.ART_GENECHAPATT v where v.champsais_cod=g.champsais_cod)
  )

GROUP BY champsais_cod, champsais_lib, enreg_s, longueurgraph_val, format_val, originecreat_val, champsaisorig_cod, unite_cod, enreg_id, champsais_lib2, pgi_typ, champ_typ, longueursais_val, precision_val, converscass_typ, saisie_ok, visible_ok, obligfocus_ok, obligval_ok, rubriqueaide_cod, msgaide_lib, infobulle_lib, presentation_typ, implicite_val
HAVING Count(1)!=2 ) r
ORDER BY champsais_cod  */

 delete from se_GEN_CHAMPSAIS;

 INSERT INTO se_GEN_CHAMPSAIS
 (SELECT m.champsais_cod,
         g.champsais_lib,
         'N' enreg_s,
         g.longueurgraph_val,
         g.format_val,
         g.originecreat_val,
         g.champsaisorig_cod,
         g.unite_cod,
         0 enreg_id,
         g.champsais_lib2,
         g.pgi_typ,
         g.champ_typ,
         g.longueursais_val,
         g.precision_val,
         g.converscass_typ,
         g.saisie_ok,
         g.visible_ok,
         g.obligfocus_ok,
         g.obligval_ok,
         g.rubriqueaide_cod,
         g.msgaide_lib,
         g.infobulle_lib,
         g.presentation_typ,
         g.implicite_val
     FROM  se_ART_GENECHAPATT m , se_VRT_ATT v,se_GEN_CHAMPSAIS_vrtatt g
     WHERE m.vrt_cod=v.vrt_cod AND m.vrtattatt_cod=v.att_cod  AND g.champsais_cod=v.champsais_cod
     );


 UPDATE se_GEN_CHAMPSAIS tf SET enreg_id=Nvl((select enreg_id FROM &erp.GEN_CHAMPSAIS f WHERE f.champsais_cod=tf.champsais_cod),0) ;
 UPDATE se_GEN_CHAMPSAIS tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;


 commit;

